package de.freudenreichdesign.webshop.model;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity
@Table (name="CUSTOMER")
public class Customer implements Serializable {

	private static final long serialVersionUID = 2220468538044544836L;
	private long customerID;
	private Person person;
	private Date dateOfBirth;
	private Date activeSince;
	private Date inactiveSince;
	
	@SuppressWarnings("unused")
	private Customer() {}
	
	public Customer(Person person, Date dateOfBirth, Date activeSince) {
		this.person = person;
		this.dateOfBirth = dateOfBirth;
		this.activeSince = activeSince;
	}
	
	@Id
	@GeneratedValue (strategy=GenerationType.AUTO)
	@Column (name="CUSTOMER_ID")
	public long getCustomerID() {
		return customerID;
	}
	
	@SuppressWarnings("unused")
	private void setCustomerID(long customerID) {
		this.customerID = customerID;
	}
	
	@Temporal (TemporalType.TIMESTAMP)
	@Column (name="ACTIVE_SINCE")
	public Date getActiveSince() {
		return activeSince;
	}
	
	public void setActiveSince(Date activeSince) {
		this.activeSince = activeSince;
	}
	
	@Temporal (TemporalType.TIMESTAMP)
	@Column (name="INACTIVE_SINCE")
	public Date getInactiveSince() {
		return inactiveSince;
	}
	
	public void setInactiveSince(Date inactiveSince) {
		this.inactiveSince = inactiveSince;
	}
	
	@Temporal (TemporalType.DATE)
	@Column (name="DATE_OF_BIRTH")
	public Date getDateOfBirth() {
		return dateOfBirth;
	}
	
	public void setDateOfBirth(Date dateOfBirth) {
		this.dateOfBirth = dateOfBirth;
	}

	@OneToOne (cascade=CascadeType.ALL, fetch=FetchType.EAGER)
	@PrimaryKeyJoinColumn (name="PERSON")
	public Person getPerson() {
		return person;
	}

	public void setPerson(Person person) {
		this.person = person;
	}
	
}
